package com.neusoft.neuiotms.dcom.controller.change;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcom.dto.change.ChangeCiPropertyDTO;
import com.neusoft.neuiotms.dcom.service.change.ChangeCiPropertyService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "配置项属性变更")
@RestController
@RequestMapping(value = "/api/w/change/ciProperty")
public class ChangeCiPropertyController {

    @Autowired
    private ChangeCiPropertyService changeCiPropertyService;

    @ApiOperation("查询所有配置项属性")
    @GetMapping
    public ResultListDTO<ChangeCiPropertyDTO> index(final Searchable searchable) {
        final List<ChangeCiPropertyDTO> changeCiPropertyDTOs = this.changeCiPropertyService.index(searchable);
        return ResultListDTO.success(changeCiPropertyDTOs);
    }

    @ApiOperation("创建配置项属性")
    @PostMapping
    public ResultDTO<ChangeCiPropertyDTO> create(@RequestBody final ChangeCiPropertyDTO dto) {
        final ChangeCiPropertyDTO result = this.changeCiPropertyService.create(dto);
        return ResultDTO.success(result);
    }

    @ApiOperation("配置项属性详情")
    @GetMapping("/{id}")
    public ResultDTO<ChangeCiPropertyDTO> details(@PathVariable final Long id) {
        final ChangeCiPropertyDTO dto = this.changeCiPropertyService.details(id);
        return ResultDTO.success(dto);
    }

    @ApiOperation("删除配置项属性")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.changeCiPropertyService.delete(id);
        return ResultDTO.success();
    }

    @ApiOperation("修改配置项属性")
    @PutMapping("/{id}")
    public ResultDTO<ChangeCiPropertyDTO> update(@PathVariable final Long id,
            @RequestBody final ChangeCiPropertyDTO dto) {
        final ChangeCiPropertyDTO result = this.changeCiPropertyService.update(id, dto);
        return ResultDTO.success(result);
    }

    @ApiOperation("分页查询所有配置项属性")
    @GetMapping("/p")
    public PageResultDTO<ChangeCiPropertyDTO> search(final Pageable pageable, final Searchable searchable) {
        return PageResultDTO.success(this.changeCiPropertyService.search(pageable, searchable));
    }

}
